package de.mizi.tilemap.renderer;

import java.awt.Graphics;

import de.mizi.tilemap.object.TilemapObjectDrawData;
import de.mizi.utility.FontData;

/**
 * This class draws a single TilemapObjectDrawData.
 * @author mizi
 *
 */
public class TilemapObjectRenderer {
	private FontData fontData;
	
	/**
	 * Constructs a new TilemapObjectRenderer object with given FontData object.
	 * @param fontData
	 */
	public TilemapObjectRenderer(FontData fontData) {
		this.fontData = fontData;
	}
	
	/**
	 * Get the width of a single tile of the tilemap this object is used for.
	 * @return the tile width
	 */
	public int getTileWidth() {
		return fontData.width;
	}
	
	/**
	 * Get the height of a single tile of the tilemap this object is used for.
	 * @return the tile height
	 */
	public int getTileHeight() {
		return fontData.height;
	}

	/**
	 * Draws a tile with the given graphics context, at the given position with
	 * the given draw data.
	 * @param g the graphics context
	 * @param x the x position
	 * @param y the y position
	 * @param drawData the draw data
	 */
	public void drawTile(Graphics g, int x, int y, TilemapObjectDrawData drawData) {
		// Background
		g.setColor(drawData.getGlyphBackground());
		g.fillRect(x, y, fontData.width, fontData.height);
		// Glyph
		g.setColor(drawData.getGlyphColor());
		g.setFont(fontData.font);
		g.drawString("" + drawData.getGlyph(), x + fontData.xCenter - (fontData.getGlyphWidth(drawData.getGlyph()) / 2), y - fontData.yOffset);
	}
}
